/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.scene.controller;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.scene.bean.ProjectAssessmentFormVO;

import com.koron.scene.service.api.ProjectAssessmentService;
import com.koron.scene.utils.BusinessCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Api(tags = "ProjectAssessment", description = "相关方考核")
@RestController
@RequestMapping("/projectAssessment")
public class ProjectAssessmentController {

    @Autowired
    private ProjectAssessmentService projectAssessmentService;

    @RequestMapping(value = "/getFormData.htm", method = RequestMethod.GET)
    @ApiOperation(value = "相关方项目考核获取评分表单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assessmentScoreId", value = "考核得分id" , dataType = "String"),
            @ApiImplicitParam(name = "assessmentFormType", value = "考核表类型" , dataType = "String"),
    })
    public MessageBean<?> getFormData(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                      String assessmentScoreId, Integer assessmentFormType) {
        if (user == null) {
            MessageBean msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return projectAssessmentService.getFormData(user, assessmentScoreId, assessmentFormType);
    }

    @RequestMapping(value = "/getAssessmentList.htm", method = RequestMethod.GET)
    @ApiOperation(value = "项目相关方-考核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "enterpriseId", value = "相关方id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "corpCode", value = "考核单位code" , dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页" , dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数" , dataType = "Integer", paramType = "query")
    })
    public MessageBean<?> getAssessmentList(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                            String projectId, String enterpriseId, Integer page, Integer pageSize, Integer assessmentType, String corpCode) {
        if (user == null) {
            MessageBean msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return projectAssessmentService.getAssessmentList(user, projectId, enterpriseId, page, pageSize, assessmentType, corpCode);
    }

    @RequestMapping(value = "/getAssessmentScoreList.htm", method = RequestMethod.GET)
    @ApiOperation(value = "项目相关方-考核-考核结果列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assessmentId", value = "考核id" , dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页" , dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数" , dataType = "Integer", paramType = "query")
    })
    public MessageBean<?> getAssessmentScoreList(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                                 String assessmentId, Integer page, Integer pageSize) {
        if (user == null) {
            MessageBean msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return projectAssessmentService.getAssessmentScoreList(user, assessmentId, page, pageSize);
    }


    @RequestMapping(value = "/saveOrUpdate.htm", method = RequestMethod.POST)
    @ApiOperation(value = "相关方项目考核保存修改分数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assessmentScoreId", value = "考核得分id" , dataType = "String"),
            @ApiImplicitParam(name = "assessmentFormType", value = "检查表类别:0项目部,1施工方,2监理方,3现场,4零散工程" , dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "考核评价" , dataType = "String"),
            @ApiImplicitParam(name = "totalScore", value = "考核总分" , dataType = "Double"),
            @ApiImplicitParam(name = "scoreTypeListStr", value = "考核手动打分的类型:0,打分细则(detailItem),1,检查细则(detail)2,为检查内容(content),3,检查项(item),4,总分(totalScore)" , dataType = "list")
    })
    public MessageBean<?> saveOrUpdate(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                       @RequestBody List<ProjectAssessmentFormVO> formList, String assessmentScoreId,
                                       Integer assessmentFormType, String comment, Double totalScore, String scoreTypeListStr) {
        if (user == null) {
            MessageBean msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return projectAssessmentService.saveOrUpdate(user, formList, assessmentScoreId, assessmentFormType, comment, totalScore, scoreTypeListStr);
    }


    @RequestMapping(value = "/initiateAssessment.htm", method = RequestMethod.POST)
    @ApiOperation(value = "发起考核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enterpriseId", value = "相关方id" , dataType = "String"),
            @ApiImplicitParam(name = "projectId", value = "项目id" , dataType = "String"),
            @ApiImplicitParam(name = "assessmentType", value = "考核类型:审核类型:0,相关方考核.1,项目考核2,建设单位(项目部)考核" , dataType = "String"),
            @ApiImplicitParam(name = "corpCode", value = "考核单位code" , dataType = "String"),
    })
    public MessageBean<?> initiateAssessment(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                             String projectId, String enterpriseId, Integer assessmentType,
                                             @RequestBody List<StaffBean> staffList, String corpCode) {

        if (user == null) {
            MessageBean msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return projectAssessmentService.initiateAssessment(user, projectId, enterpriseId, assessmentType, staffList, corpCode);
    }


    @RequestMapping(value = "/getProcessData.htm", method = RequestMethod.GET)
    @ApiOperation(value = "考核流程中获取考核得分列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assessmentId", value = "考核id" , dataType = "String"),

    })
    public MessageBean<?> getProcessData(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String assessmentId) {
        if (user == null) {
            MessageBean msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return projectAssessmentService.getProcessData(user, assessmentId);
    }

    @RequestMapping(value = "/checkAssessmentScoreState.htm", method = RequestMethod.GET)
    @ApiOperation(value = "考核流程通过前获取考核得分是否考核完成")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assessmentId", value = "考核得分id" , dataType = "String"),

    })
    public MessageBean<?> checkAssessmentScoreState(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String assessmentId) {
        if (user == null) {
            MessageBean msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return projectAssessmentService.checkAssessmentScoreState(user, assessmentId);
    }
}
